#!/usr/bin/env python
# -*- coding: utf-8 -*-
# ==================================================
# @File    : parseyamlcase
# @IDE     : PyCharm
# @Author  : liuxiangui
# @Date    : 2023/11/26 02:08
# @Describe: 
# ==================================================
import os
from library.tools.file_tool.operationFileControl import read_yaml_to_dict
from library.models import ModelAPICase, ModelAssertJson


class GetCase:
    def __init__(self, file_path):
        self.filepath = file_path
        if not os.path.exists(self.filepath):
            raise Exception("yaml用例文件不存在！")
        else:
            self._yaml_data = read_yaml_to_dict(self.filepath)
        self.case_list = []

    def get_all_case(self) -> list:
        for key, value in self._yaml_data.items():
            if key != 'common':
                case_id = key
                case_data = ModelAPICase(**value)
                case_assert_dict = {one: ModelAssertJson(**case_data.assert_data[one]) for one in case_data.assert_data.keys()}
                self.case_list.append((case_id, case_data, case_assert_dict))
        return self.case_list


if __name__ == '__main__':
    data = GetCase("../testcase/feauture/test_my_case_01.yaml")
    res = data.get_all_case()
    for i in res:
        print(i)
